import 'package:flutter/material.dart';
import 'package:lazy_food/components/keepAliveWrapper/keep_alive_arapper.dart';
import 'package:lazy_food/components/searchBar/search_bar.dart';
import 'package:lazy_food/net/network.dart';

import 'search_item.dart';

class SearchPage extends StatefulWidget {
  _SearchPageState createState() => _SearchPageState();
}

class _SearchPageState extends State<SearchPage> {
  @override
  void initState() {
    super.initState();

    
  }

  @override
  Widget build(BuildContext context) {
    double width = MediaQuery.of(context).size.width;
    return Scaffold(
      appBar: AppBar(
        title: _searchBar(),
        backgroundColor: Colors.transparent,
        automaticallyImplyLeading: false,
      ),
      backgroundColor: Colors.black,
      body: KeepAliveWrapper(
        child: ListView.builder(
          shrinkWrap: true,
          itemBuilder: (context, index) {
            return _searchGroup(index);
          },
          itemCount: 3,
        ),
      ),
    );
  }

  Widget _searchBar() {
    return SearchBar(
      height: 34,
      autofocus: true,
      hit: '搜索食材、菜谱',
      cursorColor: Colors.white,
      prefixIcon: Icon(
        Icons.search,
        color: Colors.white,
        size: 20,
      ),
      action: GestureDetector(
        child: Text(
          '取消',
          style: TextStyle(color: Colors.white, fontSize: 16),
        ),
        onTap: () {
          Navigator.pop(context);
        },
      ),
    );
  }

  Widget _searchGroup(int index) {
    return SearchItem(
      '最近搜索历史',
      action: GestureDetector(
        child: Text(
          '清除',
          style: TextStyle(color: Colors.white54, fontSize: 14),
        ),
      ),
      tags: [],
    );
  }
}
